package com.xiaotu.controller;

import com.xiaotu.service.MyAsyncService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.concurrent.Future;

@RestController
public class AsyncController {
    @Autowired
    private MyAsyncService myAsyncService;
    @GetMapping("/sendSMS")
    public String toHello() throws Exception{
        long startTime = System.currentTimeMillis();
        myAsyncService.sendSMS();
        long endTimes = System.currentTimeMillis();
        System.out.println("主流程耗时:"+(endTimes-startTime));
        return "ok";
    }
    @GetMapping("/statistics")
    public String statistics() throws Exception{
        Long stratTimes = System.currentTimeMillis();
        Future<Integer> processA = myAsyncService.processA();
        Future<Integer> processB = myAsyncService.processB();
        int total = processA.get() + processB.get();
        System.out.println("异步任务数据统计汇总结果:"+total);
        Long endTime = System.currentTimeMillis();
        System.out.println("主流程耗时"+(endTime-stratTimes));
        return "success";
    }
}
